package com.ccys.app.controller;

import com.ccys.app.feignClient.NettyFeignService;
import com.ccys.app.service.AppVersionService;
import com.ccys.common.constants.TouristApi;
import com.ccys.common.vo.ResponseResult;
import com.ccys.common.vo.ResponseResultApp;
import com.ccys.db.cache.SysCodeUtil;
import com.ccys.db.entity.SysCode;
import com.ccys.db.vo.app.launchingTheApp.VersionVo;
import feign.Request;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import static com.ccys.common.vo.ResponseResult.success;

@RestController
@RequestMapping("/common")
@Api(tags = "公用")
@SuppressWarnings("unchecked")
public class CommonApiController {

    @Autowired
    private AppVersionService appVersionService;
    @Autowired
    private NettyFeignService nettyFeignService;


    @ApiOperation("获取系统参数")
    @GetMapping(value = "/getCode")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "key", value = "key", required = true, dataType = "string", paramType = "query"),
    })
    @TouristApi
    public ResponseResult<SysCode, Object> getCode(String key,String catId) {
        return success(SysCodeUtil.getCode(key,catId));
    }

    @ApiOperation("获取所有APP版本")
    @GetMapping(value = "/GetAppVersion")
    @TouristApi
    public ResponseResultApp<VersionVo> getAppVersion() {
        return appVersionService.getAppVersion();
    }


    @TouristApi
    @ApiOperation("服务端websocket推送消息给指定用户")
    @PostMapping("sendMessageWebSocket")
    public ResponseResult sendMessageWebSocket(@RequestParam("objId") String objId, @RequestParam("msg") String msg){
        this.nettyFeignService.sendMessageWebSocket(new Request.Options(6000, 6000), objId,msg, "ok");
        return ResponseResult.success();
    }

    @TouristApi
    @ApiOperation("客服端websocket推送消息给指定用户（测试方法不能使用）")
    @PostMapping("sendMessageWebSocketToServer")
    public ResponseResult sendMessageWebSocketToServer(@RequestParam("userId") String userId, @RequestParam("msg") String msg){
        this.nettyFeignService.sendMessageWebSocketToServer(new Request.Options(6000, 6000), userId,msg, "ok");
        return ResponseResult.success();
    }

}
